﻿using System;
using System.Data;
using System.Xml;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Reflection;
using System.Configuration;
using Microsoft.Data.SqlXml;
using System.IO;

namespace ESpace.DALibrary.SqlServer
{
    public class DataAccess : DataAccessBase
    {
        protected  void InitCommand(string sqlStr, SqlParameter parameter)
        {
            this.sqlComm = new SqlCommand();
            this.sqlComm.CommandText = sqlStr;
            this.sqlComm.CommandType = CommandType.Text;
            //--------------------------------------------------------
            this.sqlComm.Parameters.Add(parameter);
            this.paramReturnValue = new SqlParameter();
            this.paramReturnValue.ParameterName = "@ReturnValue";
            this.paramReturnValue.SqlDbType = SqlDbType.Int;
            this.paramReturnValue.Size = 4;
            this.paramReturnValue.Direction = ParameterDirection.ReturnValue;
            this.sqlComm.Parameters.Add(this.paramReturnValue);
        }

        public new DataTable ExecuteDataTable(string sqlstr, SqlParameter param)
        {
            DataTable dtResult;
            using (SqlConnection sqlConn = new SqlConnection(base.ConnectionString))
            {

                InitCommand(sqlstr, param);
                sqlComm.Connection = sqlConn;
                sqlComm.CommandText = sqlstr;
                sqlComm.CommandType = CommandType.Text;
                SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlComm);

                dtResult = new DataTable();

                sqlAdapter.Fill(dtResult);
                sqlConn.Close();

                //if (sTableName != "")
                //{
                //   dtResult.TableName = sTableName;
                // }
            }
            return dtResult;
        }

    }
}
